package com.teach.demo01;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Arrays;

public class TCPClient {

	public static void main(String[] args) {
		try {
			Socket client = new Socket("192.168.31.10", 1000);
			System.out.println("连接上了服务器");
		
			OutputStream out = client.getOutputStream();
			out.write(new byte[] {65,66,67,68,69});
			out.flush();
			System.out.println("发送了一段字节数组");
			
			InputStream in = client.getInputStream();
			byte[] bs = new byte[15];
			int len = in.read(bs);
			System.out.println("接受一段服务器端发送的字节数组:"+len+" = "+Arrays.toString(bs));
		
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
}
